<template>
  <div id="app">
    <img src="./assets/logo.png">
    <div>
      <button @click="goBack">goBack</button>
      <button @click="goForward">goForward</button>
      <button @click="goHome">goHome</button>
    </div>
    <div>
      <router-link to="/">首页</router-link>
      <router-link to="/hi">hi页面</router-link>
      <!-- 这里的to属性的name一定要和router文件里的name保持映射的一致，否则无效 -->
      <router-link :to="{name: 'Hi/Hi1' , params: { username: 'cs', age: 25 }}">hi1页面</router-link>
      <router-link to="/hi/hi2">hi2页面</router-link>
      <router-link to="/params/198/cs">params页面</router-link>
      <router-link to="/goHome">goHome</router-link>
      <router-link to="/goParams/77/dd">goParams</router-link>
      <router-link to="/goHi2">goHi2</router-link>
      <router-link to="/404">404</router-link>
    </div>
    <!-- 路由切换的动效 -->
    <transition name="fade" mode="out-in">
      <router-view/>
      <router-view name="left" style="background-color: red; height: 300px; width: 50%; float: left" />
      <router-view name="right" style="background-color: gray; height: 300px; width: 50%; float: right" />
    </transition>
    <div>
      <!-- 接收路由的name值 -->
      {{ $route.name }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'App',
  methods: {
    goBack() {
      this.$router.go(-1); // -1，后退一页
    },
    goForward() {
      this.$router.go(1); // 1，前进一页
    },
    goHome() {
      this.$router.push('/'); // push(path),这个很重要的
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
.fade-enter {
  opacity: 0;
}
.fade-leave {
  opacity: 1;
}
.fade-enter-active {
  transition: opacity .5s;
}
.fade-leave-active {
  opacity: 0;
  transition: opacity .5s;

}
</style>
